/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package phd.model;

import com.sun.xml.ws.tx.at.v10.types.PrepareResponse;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 *
 * @author baez
 */
public class Course {
    
    private String name;
    private Connection con;
    private HashMap<String, String> fields;
    
    private static final String SQL_SELECT = 
            "SELECT "+
            " course_name " +
            "FROM courses " +
            "WHERE academic_year = ?";
    
    public Course(){

    }
    
    public Course(Connection con){
        this.con = con;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public List<Course> select(Integer year) throws SQLException{
        
        // lets initialize the query statement
        PreparedStatement ps = this.con.prepareStatement(SQL_SELECT);
        
        // we bind the wildcards "?" with the corresponding value
        ps.setInt(1, year);
        
        // let's execute the query
        ResultSet rs = ps.executeQuery();
        
        // All the results are in the resultset
        // and accessible via res.get{DataType}
        List<Course> list = (List<Course>)new ArrayList<Course>();
        
        while (rs.next()) {
            String _name = rs.getString("course_name");
            Course c = new Course();
            c.setName(_name);
            list.add(c);
        }
        
        ps.close();
        return list;
        
    }  
    
    
}
